<template>
    <div>
        <body id="poster">
            <el-form class="login-container" label-position="left" label-width="0px" style="background-color: azure">
                <h3 class="login_title">欢 迎 登 录</h3>
                <el-form-item>
                    <el-input type="text" v-model="uname" auto-complete="off" placeholder="账号" style="background-color: black"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-input type="password" v-model="pwd" auto-complete="off" placeholder="密码" style="background-color: black"></el-input>
                </el-form-item>
                <el-form-item style="width: 100%">
                    <el-button type="primary" style="width: 100%;background: #505458;border: none" v-on:click="login">登录</el-button>
<!--                    <el-button type="primary" style="width: 100%;background:lightblue;border: none;margin-left: 0px" v-on:click="add">注册</el-button>-->
                </el-form-item>
            </el-form>
        </body>
    </div>
</template>

<script>
    import qs from 'qs'
    export default {
        name: 'Login',
        inject:['reload'],//注入reload方法
        data () {
            return {
                uname: 'zhangsan',
                pwd: '123',
                title:'注册页面',

            }
        },
        methods: {
            login() {
                // http://localhost:8094/oauth/token?grant_type=password&client_id=manger&client_secret=123&username=15729003571&password=123
                this.$http.post("oauth/oauth/token", {
                    grant_type:'password',
                    client_id:'manger',
                    client_secret:'123',
                    username:this.uname,
                    password:this.pwd
                }).then(response => {
                    console.log(response)
                    if (response.status === 200) {
                        this.$message({
                            type: 'success',
                            message: '登录成功!'
                        });
                        var a = response.data["access_token"]
                        console.log(a)
                        sessionStorage.setItem("token", a);

                        // sessionStorage.setItem('token', response.token)
                        // localStorage.setItem("username",response.principal.username);
                        // sessionStorage.setItem('principal', JSON.stringify(response.principal))

                        this.$router.push('/main/index/yyy')
                        /*console.log(response.principal.mno)
                        if (response.principal.mno === "0"){
                            this.$router.push('/main/index/yyy')
                        }else {
                            this.$router.push('/shouye')
                        }*/

                    } else {
                        this.$message({
                            type: 'info',
                            message: '登录名或密码错误  登录失败!'
                        });
                    }
                }).catch(e => {
                    this.$message({
                        type: 'info',
                        message: '登录异常'
                    });
                })
            },
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
    #poster {
        background:url("../assets/aaa.png") no-repeat;
        background-position: center;
        height: 100%;
        width: 100%;
        background-size: cover;
        position: fixed;
    }
    body{
        margin: 0px;
        padding: 0;
    }

    .login-container {

        border-radius: 15px;
        background-clip: padding-box;
        margin: 90px auto;
        width: 350px;
        padding: 35px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;
    }

    .login_title {
        margin: 0px auto 40px auto;
        text-align: center;
        color: #505458;
    }


</style>
